/* Copyright (c) 2004-2024 peigen.info. All rights reserved. */

package info.peigen.hotpot.manage.core.service;

import info.peigen.hotpot.common.service.base.processor.ProcessorServiceContext;
import info.peigen.hotpot.common.service.base.processor.ProcessorServiceInvoke;
import info.peigen.hotpot.manage.core.service.facade.ResourceServiceFacade;
import info.peigen.hotpot.manage.core.service.order.ResourceCreateOrder;
import info.peigen.hotpot.manage.core.service.order.ResourceEditOrder;
import info.peigen.hotpot.manage.core.service.result.ResourceCreateResult;
import info.peigen.hotpot.manage.core.service.result.ResourceEditResult;
import org.noear.solon.annotation.Component;

/**
 * <b>(ResourceService)</b>
 * "资源" 服务实现
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2024-06-28
 */
@SuppressWarnings({"unused", "rawtypes"})
@Component
public class ResourceService extends AbstractHotpotManageService implements ResourceServiceFacade {

    @Override
    public ResourceCreateResult create(ResourceCreateOrder order) {
        ProcessorServiceContext serviceContext = ProcessorServiceContext.builder().order(order).result(new ResourceCreateResult()).build();
        execute(serviceContext, new ProcessorServiceInvoke() {
            @Override
            public void addProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(resourceCreateProcessor);
            }

            @Override
            public void addPostProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(resourceStoreProcessor, resourceCreateResultProcessor);
            }
        });
        return (ResourceCreateResult) serviceContext.getResult();
    }

    @Override
    public ResourceEditResult edit(ResourceEditOrder order) {
        ProcessorServiceContext serviceContext = ProcessorServiceContext.builder().order(order).result(new ResourceEditResult()).build();
        execute(serviceContext, new ProcessorServiceInvoke() {
            @Override
            public void addPreProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(resourceActiveProcessor);
            }

            @Override
            public void addProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(resourceEditProcessor);
            }

            @Override
            public void addPostProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(resourceStoreProcessor, resourceEditResultProcessor);
            }
        });
        return (ResourceEditResult) serviceContext.getResult();
    }
}